<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
           margin: 0;
           padding: 0;
        }
        body{
            height: 5000px;
        }
        #btn{
            display: none;
            position: fixed;
            bottom: 200px;
            right: 50px;
        }
        header{
            height: 200px;
            width: 100%;
            background: pink;
        }
        header section{
            width: 100%;
            height: 100px;
            background: yellow;
        }
        #wrap{
            height: 60px;
            width: 100%;
            background: #fff;
            padding: 10px 0;
            box-sizing: border-box;
            box-shadow: 0 5px 17px  -17px #000;
        }
        article{
            width: 800px;
            height: 40px;
            background: #fff;
            border: 1px solid #000;
            border-radius: 50px;
            display: flex;
            flex-direction: column;
            align-items: flex-end;
            overflow: hidden;
            margin: 0 auto;
        }
        article i{
            display: inline-block;
            background: red;
            width: 150px;
            height: 40px;
        }
    </style>
</head>
<body>
    <button id="btn">起飞</button>
    <header>
        <section></section>
    </header>
    <div id="wrap">
        <article><i></i></article>
    </div>
    <script>
        window.onscroll = function(){
            // 回到顶部
            if(scrollY >= 1000){
                console.log('11')
                btn.style.display = 'block'
            }else{
                btn.style.display = 'none'
            }

            // 淘宝效果
            if(scrollY >= 260){
                wrap.style.position = 'fixed'
                wrap.style.top = '0'
            }else if (scrollY <= 260){
                wrap.style.position = 'absolute'
                wrap.style.top = '200px'
            }

        }

        // 回到顶部
        var timer = null
        btn.onclick = function(){
                clearInterval(timer)
           timer = setInterval(function(){
                if(scrollY <= 0 ){
                    clearInterval(timer)
                }
                scrollTo({ top: scrollY - 100 })
           },10)
        }


        
    </script>
</body>
</html>